<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('修改人员信息')" />
    <th:block th:include="include :: datetimepicker-css" />
</head>
<body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
    <form class="form-horizontal m" id="form-wzxUser-edit" th:object="${sysWzxUser}">
        <input name="userId" th:field="*{userId}" type="hidden">
        <input name="deptId" type="hidden" id="treeId" th:field="*{deptId}" />
        <div class="form-group">
            <label class="col-sm-3 control-label">部门：</label>
            <div class="col-sm-8">
                <input name="deptName" onclick="selectDeptTree()" id="treeName" type="text" placeholder="默认现在所属部门" class="form-control">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">人员姓名：</label>
            <div class="col-sm-8">
                <input name="userName" th:field="*{userName}" class="form-control" type="text">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label " >开始时间：</label>
            <div class="col-sm-8">
                <div class="input-group date">
                    <input name="createTime" th:value="${#dates.format(sysWzxUser.createTime, 'yyyy-MM-dd')}" class="form-control  creatTime" placeholder="yyyy-MM-dd" type="text">
                    <span class="input-group-addon hiddenSome"><i class="fa fa-calendar"></i></span>
                </div>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">结束时间：</label>
            <div class="col-sm-8">
                <div class="input-group date">
                    <input name="endTime" th:value="${#dates.format(sysWzxUser.endTime, 'yyyy-MM-dd')}" class="form-control  endTime" placeholder="yyyy-MM-dd" type="text">
                    <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                </div>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">协同人：</label>
            <div class="col-sm-8">
                <input name="withWork" th:field="*{withWork}" class="form-control  withWork" type="text">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">目的地：</label>
            <div class="col-sm-8">
                <input name="dest" th:field="*{dest}" class="form-control  dest" type="text">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">原因：</label>
            <div class="col-sm-8">
                <input name="reason" th:field="*{reason}" class="form-control  reason" type="text">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">状态：</label>
            <div class="col-sm-8">
                <!--                    <input name="state" th:field="*{state}" class="form-control" type="text">-->
                <select name="state" id="state" th:field="*{state}" class="form-control">
                    <option value="事假">事假</option>
                    <option value="正常">正常</option>
                    <option value="病假">病假</option>
                </select>
            </div>
        </div>
    </form>
</div>
<th:block th:include="include :: footer" />
<th:block th:include="include :: datetimepicker-js" />
<script th:inline="javascript">
    var prefix = ctx + "system/wzxUser";
    $("#form-wzxUser-edit").validate({
        focusCleanup: true
    });

    function submitHandler() {
        if ($.validate.form()) {
            $.operate.save(prefix + "/edit", $('#form-wzxUser-edit').serialize());
        }
    }

    $("input[name='endTime'],input[name='createTime']").datetimepicker({
        format: "yyyy-mm-dd",
        minView: "month",
        autoclose: true
    });

    var createTime = $('.creatTime').val();
    var endTime = $('.endTime').val()
    var withWork = $('.withWork').val();
    var dest = $('.dest').val();
    var reason = $('.reason').val();

    $("#state").bind("input propertychange",function(event){
        console.log($('#state').val() == "正常")
        console.log(createTime)

        if($('#state').val() == "正常"){
            $('.creatTime').val(null);
            $('.endTime').val(null);
            $('.withWork').val(null);
            $('.dest').val(null);
            $('.reason').val(null);
        }else{
            console.log(createTime)
            $('.creatTime').val([[${#dates.format(sysWzxUser.createTime, 'yyyy-MM-dd')}]]);
            $('.endTime').val(endTime);
            $('.withWork').val(withWork);
            $('.dest').val(dest);
            $('.reason').val(reason);
        }
    });

    /* 用户管理-新增-选择部门树 */
    function selectDeptTree() {
        var treeId = $("#treeId").val();
        var deptId = $.common.isEmpty(treeId) ? "100" : $("#treeId").val();
        var url = ctx + "system/user/selectDeptTree/" + deptId;
        var options = {
            title: '选择部门',
            width: "380",
            url: url,
            callBack: doSubmit
        };
        console.log(deptId)
        $.modal.openOptions(options);
    }

    function doSubmit(index, layero){
        var body = $.modal.getChildFrame(index);
        $("#treeId").val(body.find('#treeId').val());
        $("#treeName").val(body.find('#treeName').val());
        $.modal.close(index);
    }

</script>
</body>
</html>